var common = require('../../utils/common.js');
const app = getApp()
Page({
  data: {
    subordinate:[],
    page:1
  },
  onLoad: function (options) {
    this.getSubordinate()
  },
  getSubordinate(){
    const that = this
    common.post({
      url: '/app/user/listInvitatory', data: { sessionId: app.globalData.sessionId, pageNo: 1 }
    })
      .then((res) => {
        console.log(res.data)
        if (res.data.code == 0) {
          that.setData({
            subordinate: res.data.data
          })
        }
      }).catch((res) => {
        console.log(res)
        app.timeOutTip()
      })
  },
  getSubordinatePage(){
    const that = this;
    var page = that.data.page + 1;
    common.post({ url: '/app/user/listInvitatory', data: { sessionId: app.globalData.sessionId, pageNo: page } })
      .then((res) => {
        var data = that.data.subordinate;
        console.log(res.data)
        if (that.data.page * 10 < res.data.total) {
          that.setData({
            page: page
          });
          var postList = res.data.data;
          for (let i = 0; i < postList.length; i++) {
            let tmp = postList[i];
            data.push(tmp);
            console.log(data)
            that.setData({
              subordinate: data,
            })
          }
        } else {
          console.log('没有了')
          wx.showToast({
            title: '没有了',
            icon: 'none',
            duration: 2000
          })
        }

      }).catch((res) => {
        console.log(res)

      })
  },
  onReachBottom() {
    this.getSubordinatePage()
  },
})